var zh = document.querySelector(".zhanghao");
var mm = document.querySelector(".mima");
var zhang = document.querySelector(".zhang");
var mi = document.querySelector(".mi");
var li = document.querySelector(".li");
var but = document.querySelector('button');
var yi=false;
var er=false;
zh.onblur=function(){
  var username=zh.value
  var reg=/^\S{6,11}$/
  if(reg.test(username)){
      yi=true
      zhang.innerHTML="格式正确"
      zhang.style.color="greenyellow"
  }else{
      yi=false
      zhang.innerHTML="请输入6-11位数字"
  }
}

mm.onblur=function(){
  var password=mm.value
  var reg=/^\S{6,11}$/
  if(reg.test(password)){
      er=true
      mi.innerHTML="格式正确"
      mi.style.color="greenyellow"
  }else{
      er=false
      mi.innerHTML="请输入6-11位数字"
  }
}

li.onclick = function () {
  if(yi==true&&er==true){
  axios.get("http://jx.xuzhixiang.top/ap/api/reg.php", {
      params: {
        username: zh.value,
        password: mm.value,
      },
    })
    .then((resData) => {
      // console.log(resData);
      var data = resData.data;
      // console.log(data);
      if (data.code == 0) {
        alert("用户名已存在，请重试");
      } else {
        alert('注册成功,请登录')
      }
    })
  }else{
    alert("请核对账号或密码格式")
  }
};
var ji = 1;
but.onclick= function () {

  if (ji == 1) {
    mm.type = 'password';
      this.innerHTML = '显'
      ji = 0;
  } else {
    mm.type = 'Text';
      this.innerHTML = '隐'
      ji = 1
  }
}